-- [tsx]: Button.tsx
local ____exports = {} -- 1
local ____Dora = require("Dora") -- 2
local Node = ____Dora.Node -- 2
local Sprite = ____Dora.Sprite -- 2
local Label = ____Dora.Label -- 2
local Vec2 = ____Dora.Vec2 -- 2
local thread = ____Dora.thread -- 2
local sleep = ____Dora.sleep -- 2
local Color = ____Dora.Color -- 2
____exports.ButtonState = ButtonState or ({}) -- 10
____exports.ButtonState.Normal = "normal" -- 11
____exports.ButtonState.Hover = "hover" -- 12
____exports.ButtonState.Pressed = "pressed" -- 13
____exports.ButtonType = ButtonType or ({}) -- 17
____exports.ButtonType.Click = "click" -- 18
____exports.ButtonType.Toggle = "toggle" -- 19
____exports.Button = function(props) -- 44
	local ____props_0 = props -- 66
	local ____type = ____props_0.type -- 66
	if ____type == nil then -- 66
		____type = ____exports.ButtonType.Click -- 47
	end -- 47
	local x = ____props_0.x -- 47
	if x == nil then -- 47
		x = 0 -- 48
	end -- 48
	local y = ____props_0.y -- 48
	if y == nil then -- 48
		y = 0 -- 49
	end -- 49
	local width = ____props_0.width -- 49
	if width == nil then -- 49
		width = 200 -- 50
	end -- 50
	local height = ____props_0.height -- 50
	if height == nil then -- 50
		height = 100 -- 51
	end -- 51
	local onClick = ____props_0.onClick -- 51
	if onClick == nil then -- 51
		onClick = function() -- 52
		end -- 52
	end -- 52
	local onDoubleClick = ____props_0.onDoubleClick -- 52
	if onDoubleClick == nil then -- 52
		onDoubleClick = function() -- 53
		end -- 53
	end -- 53
	local onStateChange = ____props_0.onStateChange -- 53
	if onStateChange == nil then -- 53
		onStateChange = function() -- 54
		end -- 54
	end -- 54
	local normalImage = ____props_0.normalImage -- 54
	if normalImage == nil then -- 54
		normalImage = "Image/button/button.clip|button_up" -- 55
	end -- 55
	local pressImage = ____props_0.pressImage -- 55
	if pressImage == nil then -- 55
		pressImage = "Image/button/button.clip|button_down" -- 56
	end -- 56
	local text = ____props_0.text -- 56
	if text == nil then -- 56
		text = "" -- 57
	end -- 57
	local fontName = ____props_0.fontName -- 57
	if fontName == nil then -- 57
		fontName = "sarasa-mono-sc-regular" -- 58
	end -- 58
	local fontSize = ____props_0.fontSize -- 58
	if fontSize == nil then -- 58
		fontSize = 40 -- 59
	end -- 59
	local color = ____props_0.color -- 59
	if color == nil then -- 59
		color = Color(4294967295) -- 60
	end -- 60
	local textWidth = ____props_0.textWidth -- 60
	if textWidth == nil then -- 60
		textWidth = Label.AutomaticWidth -- 61
	end -- 61
	local alignment = ____props_0.alignment -- 61
	if alignment == nil then -- 61
		alignment = "Center" -- 62
	end -- 62
	local tag = ____props_0.tag -- 62
	if tag == nil then -- 62
		tag = 0 -- 63
	end -- 63
	local textpos = ____props_0.textpos -- 63
	if textpos == nil then -- 63
		textpos = Vec2(0, 0) -- 64
	end -- 64
	local root = Node() -- 69
	root.x = x -- 70
	root.y = y -- 71
	local buttonUp = Sprite(normalImage) -- 74
	if buttonUp then -- 74
		buttonUp.position = Vec2(0, 0) -- 76
		buttonUp.width = width -- 77
		buttonUp.height = height -- 78
		root:addChild(buttonUp) -- 79
	end -- 79
	local buttonDown = Sprite(pressImage) -- 83
	if buttonDown then -- 83
		buttonDown.position = Vec2(0, 0) -- 85
		buttonDown.width = width -- 86
		buttonDown.height = height -- 87
		buttonDown.visible = false -- 88
		root:addChild(buttonDown) -- 89
	end -- 89
	local buttonLabel = Label(fontName, fontSize) -- 94
	if buttonLabel then -- 94
		buttonLabel.text = text -- 96
		buttonLabel.position = textpos -- 97
		buttonLabel.textWidth = textWidth -- 98
		buttonLabel.alignment = alignment -- 99
		buttonLabel.color = color -- 100
		root:addChild(buttonLabel) -- 101
	end -- 101
	local clickNode = Node() -- 104
	clickNode.width = width -- 105
	clickNode.height = height -- 106
	root:addChild(clickNode) -- 107
	local state = ____exports.ButtonState.Normal -- 110
	local tempchange = false -- 111
	local switched = false -- 112
	local visible = true -- 113
	local doubleClick = false -- 114
	local function setState(newState) -- 117
		state = newState -- 118
		if buttonUp and buttonDown then -- 118
			local pressed = state == ____exports.ButtonState.Pressed -- 120
			buttonUp.visible = not pressed -- 121
			buttonDown.visible = pressed -- 122
		end -- 122
		onStateChange(newState) -- 124
	end -- 117
	clickNode:onTapBegan(function(touch) -- 128
		if state == ____exports.ButtonState.Normal then -- 128
			tempchange = true -- 130
			setState(____exports.ButtonState.Pressed) -- 131
			return true -- 132
		end -- 132
		return false -- 134
	end) -- 128
	clickNode:onTapEnded(function() -- 137
		if tempchange then -- 137
			setState(____exports.ButtonState.Normal) -- 139
			tempchange = false -- 140
		end -- 140
	end) -- 137
	clickNode:onTapped(function() -- 144
		if ____type == ____exports.ButtonType.Click then -- 144
			setState(____exports.ButtonState.Normal) -- 146
			thread(function() -- 147
				sleep(0.3) -- 148
				if doubleClick then -- 148
					doubleClick = false -- 150
					onClick(switched, tag) -- 151
				end -- 151
			end) -- 147
			if doubleClick then -- 147
				doubleClick = false -- 156
				onDoubleClick(tag) -- 157
			else -- 157
				doubleClick = true -- 160
			end -- 160
		else -- 160
			switched = not switched -- 163
			setState(switched and ____exports.ButtonState.Pressed or ____exports.ButtonState.Normal) -- 164
			onClick(switched, tag) -- 165
		end -- 165
		return true -- 168
	end) -- 144
	local function setVisible(tempvisible) -- 171
		visible = tempvisible -- 172
		if buttonDown and buttonUp and buttonLabel then -- 172
			if visible then -- 172
				local pressed = state == ____exports.ButtonState.Pressed -- 175
				buttonUp.visible = not pressed -- 176
				buttonDown.visible = pressed -- 177
				buttonLabel.visible = true -- 178
				root:addChild(clickNode) -- 179
			else -- 179
				buttonUp.visible = false -- 181
				buttonDown.visible = false -- 182
				buttonLabel.visible = false -- 183
				clickNode:removeFromParent(false) -- 184
			end -- 184
		end -- 184
	end -- 171
	local function setText(temptext) -- 188
		if buttonLabel then -- 188
			buttonLabel.text = temptext -- 191
		end -- 191
	end -- 188
	local buttonNode = {node = root, setText = setText} -- 195
	return buttonNode -- 196
end -- 44
return ____exports -- 44